package ird.demo.common;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FormatUtil {
	public static final DateFormat LDAP_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
	public static final DateFormat LDAP_DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	public static final DateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy");
	public static final DateFormat DATETIME_FORMAT = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
	public static final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");
	
	public static Timestamp toLdapTimestamp(String timestampStr) throws Exception{
		Date ts = LDAP_DATETIME_FORMAT.parse(timestampStr);
		return new Timestamp(ts.getTime());
	}
	
	public static String formatDate(Date aDate){
		return DATE_FORMAT.format(aDate);
	}
	
	public static String formatTime(Date aDate){
		return TIME_FORMAT.format(aDate);
	}
	
	public static Date toDate(String dateStr) throws Exception{
		return DATE_FORMAT.parse(dateStr);
	}
}
